package Offer_03;

import java.util.Arrays;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/31 11:40
 * 剑指 Offer 03. 数组中重复的数字
 */
public class Solution {
    public int findRepeatNumber(int[] nums) {
        Arrays.sort(nums);
        int cur = 0,next = 1;
        while (next<nums.length){
            if (nums[cur]==nums[next]){
                return nums[cur];
            }
            cur++;
            next++;
        }
        return -1;
    }
    public int findRepeatNumber1(int[] nums) {
        int[] a = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            a[nums[i]]++;
            if (a[nums[i]] > 1){
                return nums[i];
            }
        }
        return -1;
    }
}
